<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>打印预览</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="format-detection" content="telephone=no">
		<!-- jQuery-->
		<script type="text/javascript" src="/static/plugins/jquery/jquery-3.6.0.min.js"></script>

		<!-- layui-->
		<link rel="stylesheet" href="/static/plugins/layui/2.7.6/css/layui.css" media="all">
		<script src="/static/plugins/layui/2.7.6/layui.js" charset="utf-8"></script>

		<!-- common -->
		<link rel="stylesheet" href="/static/admin/css/common.css" media="all" />
		<link rel="stylesheet" href="/static/admin/css/mini-ease.css" media="all" />
		<script src="/static/plugins/printWorld/PrintWorld.js"></script>
		
	</head>

	
	<body>

	<!-- 列表 -->
	<div class="layui-row layui-col-space5" style="width:90%;margin: 0 auto;">
		<div class="layui-col-md12" id="id_panel_left_grid">
			<div class="layui-panel" style="overflow: auto; padding-top: 0.2rem;">
				<div class="mid-content">

					<table class="layui-hide" id="main_table" lay-filter="main_table"></table>

					<script type="text/html" id="toolbarDemo">
						<div class="layui-row" style="height: 40px;" id="toolbarDemoBtn">
							<div class="layui-col-xs12">
								<button type="button" class="layui-btn layui-btn-sm" lay-on="printGoods-all" id="printGoodsAllBtn" onclick="printGoodsAll()">
									<i class="layui-icon layui-icon-ok-circle layui-font-12"></i> 打印全部商品标
								</button>
								<button type="button" class="layui-btn layui-btn-sm" lay-on="printTransparent-all" id="printTransparentAllBtn" onclick="printTransparentAll()">
									<i class="layui-icon layui-icon-ok-circle layui-font-12"></i> 打印全部透明标
								</button>
								<button type="button" class="layui-btn layui-btn-sm" lay-on="printEur-all" id="printEurAllBtn" onclick="printEurAll()">
									<i class="layui-icon layui-icon-ok-circle layui-font-12"></i> 打印全部欧代标
								</button>


							</div>

						</div>
					</script>
					<script type="text/html" id="templet_index_no">{{d.LAY_TABLE_INDEX+1}}</script>
				</div>
			</div>
		</div>
	</div>


	<input type="hidden" name="bid" id="bid" value=""><!--装箱单号-->
	<input type="hidden" name="printType" id="printType" value=""><!--打印类型：0商品标、1透明标、2欧代标-->

      <script>

		  $('#bid').val('[(${bid})]');//单号
		  $('#printType').val('[(${printType})]');//打印类型：0商品标、1透明标、2欧代标


		  var dataList = [];

		  //获取列表数据
		  $.ajax({
			  url : '/api/inter/tccFbaBoxUp/printTypeSearchList',
			  data : {bid:$('#bid').val(),printType:$('#printType').val()},
			  type : 'POST',
			  async : false,//关闭异步
			  success : function(result) {
				  if (result.code == '0') {
					  dataList = result.data;
				  }else{
					  layer.msg(result.msg);
				  }
			  }
		  });
		  layui.config({
				//自定义layui组件的目录,设定扩展的layui模块的所在目录，一般用于外部模块扩展
				base: '/static/js/layui_extends/'
			}).use(['form', 'element', 'table', 'dropdown', 'util', 'laydate', 'upload', 'YsModal'], function(){
					  var element = layui.element;
					  var table = layui.table;
					  var dropdown = layui.dropdown;
					  var form = layui.form;
					  var util = layui.util;
					  var $ = layui.jquery;
					  var laydate = layui.laydate;
					  var upload = layui.upload;

			  		  var cols =[ //表头
						  [
							  {title: '', type: 'checkbox',  unresize: true, width: '40'},
							  {title: '序号',   align:"center",type:"numbers"},
							  {title: '商品编码', width: '100' , field:'commodityCode', align:"center"},
							  {title: '商品名称', width: '150' , field:'commodityName', align:"center"},
							  {title: 'ASIN', width: '100' , field:'asin', align:"center"},
							  {title: 'SKU', width: '100' , field:'sku', align:"center"},
							  {title: 'FNSKU', width: '100' , field:'fnSku', align:"center"},
							  {title: '计划发货数量', width: '100' , field:'numPlanDeliver', align:"center"},
							  {title: '透明标记编码', width: '100' , field:'signCode', align:"center"},
							  {title: '打印状态', width: '200' , field:'statusPrint', align:"center"},
							  {title: '打印商品标', width: '100' , align:"center",templet:
										  function(d){
											  var str = '';
											  if(d.isPrintGoods == '1'){
												  str += '<button type="button" class="layui-btn layui-btn-xs layui-bg-blue" onclick="printGoodsByOne(\''+d.planItemId+'\',\'' + d.numPlanDeliver + '\');">打印商品标</button>';
											  }
											  return str;
										  }
							  },
							  {title: '打印透明标', width: '100' , align:"center",templet:
										  function(d){
											  var str = '';
											  if(d.isPrintTransparent == '1'){
												  str += '<button type="button" class="layui-btn layui-btn-xs layui-bg-blue" onclick="printTransparentByOne(\''+d.annexFile+'\',\''+d.planItemId+'\');">打印透明标</button>';
											  }
											  return str;
										  }
							  },
							  {title: '打印欧代标', width: '100' , align:"center",templet:
										  function(d){
											  var str = '';
											  if(d.isPrintEur == '1'){
												  str += '<button type="button" class="layui-btn layui-btn-xs layui-bg-blue" onclick="printEurByOne(\''+d.planItemId+'\',\'' + d.numPlanDeliver + '\');">打印欧代标</button>';
											  }
											  return str;
										  }
							  },
							  // {title: '打印商品标', width: '120' , align:"center",templet:
								// 		  function(d){
								// 			  var str = '';
								// 			  //$('#printType').val('[(${printType})]');//打印类型：0商品标、1透明标、2欧代标
								// 			  var printType = $('#printType').val();
								// 			  if(d.isPrint == '1'){
								// 				  if(printType=='0'){
								// 					  str += '<button type="button" class="layui-btn layui-btn-sm layui-btn-normal" onclick="printGoodsByOne(\''+d.planItemId+'\',\'' + d.numPlanDeliver + '\');">打印商品标</button>';
								// 				  }else if(printType=='1'){
								// 					  str += '<button type="button" class="layui-btn layui-btn-sm layui-btn-normal" onclick="printTransparentByOne(\''+d.annexFile+'\',\''+d.planItemId+'\');">打印透明标</button>';
								// 				  }else if(printType=='2'){
								// 					  str += '<button type="button" class="layui-btn layui-btn-sm layui-btn-normal" onclick="printEurByOne(\''+d.planItemId+'\',\'' + d.numPlanDeliver + '\');">打印欧代标</button>';
								// 				  }
								// 			  }
								// 			  return str;
								// 		  }
							  // },

						  ]
					  ];
					  // 创建渲染实例
					  table.render({
						  id:'main_table'
						  ,elem: '#main_table'
						  ,data:dataList
						  ,toolbar: '#toolbarDemo'
						  ,defaultToolbar: [ 'filter',{
							  title: '刷新页面'
							  ,layEvent: 'LAYTABLE_REFRESH'
							  ,icon: 'layui-icon-refresh'
						  }]
						  ,height: window.innerHeight - 70 // 最大高度减去其他容器已占有的高度差
						  ,where: {}
						  ,cellMinWidth: 95
						  ,limit : 20
						  ,limits : [20,50,200,500]
						  ,page: true
						  ,request: {
							  pageName: 'page',
							  limitName: 'size'
						  }
						  //,skin: 'row'
						  ,even: false // 开启隔行背景
						  ,skin: 'grid'//设置表格边框风格
						  ,cols:cols
						  ,done: function(res){

						  }
						  ,error: function(res, msg){
							  console.log(res, msg)
						  }
					  });


					  // 工具栏事件
					  table.on('toolbar(main_table)', function(obj){
						  var id = obj.config.id;
						  var checkStatus = table.checkStatus(id);
                          var datas = checkStatus.data;
						  var othis = lay(this);
						  switch(obj.event){
                              case 'LAYTABLE_REFRESH':
							  {
								  layer.confirm("确定刷新吗？",{
									  btn: ['确定', '取消']
								  }, function (index) {
									  location.reload();
									  layer.close(index);
								  });
								  break;
							  }

						  };
					  });

					  // 普通事件
					  util.on('lay-on', {
					  	/*
						  //打印全部商品标
						  "printGoods-all": function(){

						  },
						  //打印全部透明标
						  "printTransparent-all": function(){

						  },
						  //打印全部欧代标
						  "printEur-all": function(){

						  },
					  	 */
					  })

				  });



		  //打印商品标
		  function printGoodsByOne(planItemId,numPlanDeliver) {
			  var json = {};
			  json.action = "print";	//打印指令动作。json.action = "preview"，则生成预览。
			  json.template = window.location.href.split("/web")[0] + "/static/plugins/printWorld/muban/goods_20240808.fmx";	//模板URL，位于WEB服务器的一个模板文件。
			  //获取列表数据
			  $.ajax({
				  url : '/api/inter/tccFbaBoxUp/getGoodsPrintInfo',
				  data : {bid:$('#bid').val(),planItemId:planItemId},
				  type : 'POST',
				  async : false,//关闭异步
				  success : function(result) {
					  if (result.code == '0') {
						  if (numPlanDeliver != null){
							  alert("！打印的份数是：" + numPlanDeliver + "份，可在预览页面右下角设置每页显示最多10个");
						  }
						  var rows = result.data;
						  var datas = [];
						  for(var i = 0; i < rows.length; i++) {
							  var row = rows[i];
							  for(var j = 0; j < row.num; j++) {
								  datas.push({
									  "barcode": row.imgBarcode,
									  "barcodetext": row.imgBarcode,
									  "nameEn": row.nameEn,
									  "nameCn": row.nameCn,
								  });
							  }
							  if(i != rows.length) {
								  datas.push({
									  "barcode": '',
									  "barcodetext": '',
									  "nameEn": '',
									  "nameCn": '',
								  });
							  }
						  }
						  json.data = datas;
						  json.action = "preview";
						  var pw = GetPrintWorld();	//获取打天下对象
						  pw.Act(json);
						  updateTagState(0,planItemId,0);//变更状态
					  }else{
						  layer.msg(result.msg);
					  }
				  }
			  });
		  }

		  //打印全部商品标
		  function printGoodsAll(){
			  var json = {};
			  json.action = "print";	//打印指令动作。json.action = "preview"，则生成预览。
			  json.template = window.location.href.split("/web")[0] + "/static/plugins/printWorld/muban/goods_20240807.fmx";	//模板URL，位于WEB服务器的一个模板文件。
			  //获取列表数据
			  $.ajax({
				  url : '/api/inter/tccFbaBoxUp/getGoodsPrintInfo',
				  data : {bid:$('#bid').val()},
				  type : 'POST',
				  async : false,//关闭异步
				  success : function(result) {
					  if (result.code == '0') {
						  var rows = result.data;
						  var datas = [];
						  for(var i = 0; i < rows.length; i++) {
							  var row = rows[i];
							  for(var j = 0; j < row.num; j++) {
								  datas.push({
									  "barcode": row.imgBarcode,
									  "barcodetext": row.imgBarcode,
									  "nameEn": row.nameEn,
									  "nameCn": row.nameCn,
								  });
							  }
							  if(i != rows.length) {
								  datas.push({
									  "barcode": '',
									  "barcodetext": '',
									  "nameEn": '',
									  "nameCn": '',
								  });
							  }
						  }
						  json.data = datas;
						  json.action = "print";
						  var pw = GetPrintWorld();	//获取打天下对象
						  pw.Act(json);
						  updateTagState(1,null,0);//变更状态
					  }else{
						  layer.msg(result.msg);
					  }
				  }
			  });



		  }

		  //打印透明标
		  function printTransparentByOne(annexFile,planItemId) {
			  var json = {};
			  json.action = "previewfile";	//打印指令动作。json.action = "preview"，则生成预览。
			  json.format = "pdf_url";        //指定格式为pdf_url。 //指定格式为pdf_url。

			  json.docwidth = 5; // 单位：cm
			  json.doclength = 2.2; // 单位：cm
			  json.paperwidth = 5;
			  json.paperlength = 3;
			  json.content = annexFile;   //pdf文件的url路径
			  // json.template = window.location.href.split("/web")[0] + "/static/plugins/printWorld/pdf_mini-ease.com.ctf";
			  // json.template = "https://file.mini-ease.com/upload/nomodule/202412/13/163232652.ctf";
			  json.cert = "https://file.mini-ease.com/upload/nomodule/202412/13/163232652.ctf";
			  var pw = GetPrintWorld();    //获取打天下对象
			  pw.Act(json);

			  updateTagState(0,planItemId,1);//变更状态
		  }
		  //打印全部透明标
		  function printTransparentAll(){

			  var pdfs = [];
			  for(var i = 0; i < dataList.length; i++) {

			  	if(dataList[i].annexFile!=null && dataList[i].annexFile!=''){
					if (i != 0){
						pdfs.push('https://file.mini-ease.com/upload/static/tmb_blank.pdf');
					}
					pdfs.push(dataList[i].annexFile);
				}
			  }

			  var json = {};
			  json.action = "previewfile";	//打印指令动作。json.action = "preview"，则生成预览。
			  json.format = "pdf_url";        //指定格式为pdf_url。 //指定格式为pdf_url。

			  json.docwidth = 5; // 单位：cm
			  json.doclength = 2.2; // 单位：cm
			  json.paperwidth = 5;
			  json.paperlength = 3;

			  json.content = pdfs;   //pdf文件的url路径
			  // json.cert = window.location.href.split("/web")[0] + "/static/plugins/printWorld/pdf_mini-ease.com.ctf";
			  json.cert = "https://file.mini-ease.com/upload/nomodule/202412/13/163232652.ctf";
			  var pw = GetPrintWorld();    //获取打天下对象
			  pw.Act(json);

			  updateTagState(1,null,1);//变更状态
		  }
		  //打印欧代标
		  function printEurByOne(planItemId,numPlanDeliver) {
			  var json = {};
			  json.action = "previewfile";	//打印指令动作。json.action = "preview"，则生成预览。
			  json.format = "pdf_url";        //指定格式为pdf_url。
			  json.paperwidth = 10;
			  json.paperlength = 10;
			  //获取列表数据
			  $.ajax({
				  url : '/api/inter/tccFbaBoxUp/europeanStandardPrint',
				  data : {bid:$('#bid').val(),planItemId:planItemId},
				  type : 'POST',
				  async : false,//关闭异步
				  success : function(result) {
					  if (result.code == '0') {
						  if (numPlanDeliver != null){
							  alert("！打印的份数是：" + numPlanDeliver + "份，可在预览页面右下角设置每页显示最多10个");
						  }
						  json.content = result.msg;   //pdf文件的url路径
						  // json.template = window.location.href.split("/web")[0] + "/static/plugins/printWorld/pdf_mini-ease.com.ctf";
						  // json.template = "https://file.mini-ease.com/upload/nomodule/202412/13/163232652.ctf";
						  json.cert = "https://file.mini-ease.com/upload/nomodule/202412/13/163232652.ctf";
						  var pw = GetPrintWorld();    //获取打天下对象
						  pw.Act(json);
						  updateTagState(0,planItemId,2);//变更状态
					  }else{
						  layer.msg(result.msg);
					  }
				  }
			  });
		  }

		  //打印欧代标
		  function printEurAll() {
			  var json = {};
			  json.action = "previewfile";	//打印指令动作。json.action = "preview"，则生成预览。
			  json.format = "pdf_url";        //指定格式为pdf_url。
			  json.paperwidth = 10;
			  json.paperlength = 10;
			  //获取列表数据
			  $.ajax({
				  url : '/api/inter/tccFbaBoxUp/europeanStandardPrint',
				  data : {bid:$('#bid').val()},
				  type : 'POST',
				  async : false,//关闭异步
				  success : function(result) {
					  if (result.code == '0') {
						  json.content = result.msg;   //pdf文件的url路径
						  // json.template = window.location.href.split("/web")[0] + "/static/plugins/printWorld/pdf_mini-ease.com.ctf";
						  // json.template = "https://file.mini-ease.com/upload/nomodule/202412/13/163232652.ctf";
						  json.cert = "https://file.mini-ease.com/upload/nomodule/202412/13/163232652.ctf";
						  var pw = GetPrintWorld();    //获取打天下对象
						  pw.Act(json);
						  updateTagState(1,null,2);//变更状态
					  }else{
						  layer.msg(result.msg);
					  }
				  }
			  });
		  }



		  //修改对应标签状态
		  //oneOrAll 单条（0） or 全部 （1）
		  //planItemId 计划单子表id
		  function updateTagState(oneOrAll,planItemId,printType) {
			  $.ajax({
				  type: "POST",
				  url: '/api/inter/tccFbaBoxUp/updateTagState',
				  data: {
					  bid: $('#bid').val(),
					  printType:printType,
					  oneOrAll:oneOrAll,
					  planItemId:planItemId
				  },
				  success: function (data) {
					  if (data.code == 0) {
						  //layer.alert(data.msg);
					  } else {
						  layer.alert(data.msg);
					  }
				  }, error: function() {
					  layer.close();
					  layer.msg("变更打印状态失败，请稍后再试！", { icon: 2 });
				  }
			  });
		  }
		  

      </script>

  </body>
</html>